package com.ruibang.glass.equipment.controller;


import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ruibang.glass.equipment.constant.Constants;
import com.ruibang.glass.equipment.domain.req.device.DeviceAllPageReq;
import com.ruibang.glass.equipment.entity.device.SparePartsInventory;
import com.ruibang.glass.equipment.service.SparePartsInventoryService;
import com.teaming.cloud.framework2.common.model.ResultBody;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * <p>
 * 备件台账
 * </p>
 *
 * @author mameng
 * @since 2024-03-20
 */
@RestController
@RequestMapping("/api/equipment/spare/parts/inventory")
@Api(value = "备件台账")
public class SparePartsInventoryController {
    @Autowired
    private SparePartsInventoryService sparePartsInventoryService;

    @PostMapping("list")
    @ApiOperation(value = "仓库管理列表", response = ResultBody.class)
    public ResultBody getBoilerList(@RequestBody DeviceAllPageReq deviceAllPageReq) {
        return ResultBody.success(sparePartsInventoryService.queryPage(deviceAllPageReq));
    }

    @PostMapping("addOrUpdateCheck")
    @ApiOperation(value = "修改添加", response = ResultBody.class)
    public ResultBody addChild(@RequestBody SparePartsInventory repairWorkOrder) {
        return ResultBody.success(sparePartsInventoryService.updateOrAddById(repairWorkOrder));
    }


    //
    @PostMapping("deleteAll")
    @ApiOperation(value = "删除", response = ResultBody.class)
    public ResultBody deleteAll(@RequestBody SparePartsInventory repairWorkOrder) {
        sparePartsInventoryService.lambdaUpdate().eq(SparePartsInventory::getId, repairWorkOrder.getId()).set(SparePartsInventory::getIsDelete, Constants.ONE_STR).update();
        return ResultBody.success();
    }


    @PostMapping("getOne")
    @ApiOperation(value = "查看详情", response = ResultBody.class)
    public ResultBody getOne(@RequestBody SparePartsInventory repairWorkOrder) {
        return ResultBody.success(sparePartsInventoryService.getById(repairWorkOrder.getId()));
    }

    @GetMapping("getNameList")
    @ApiOperation(value = "出入库获取名称", response = ResultBody.class)
    public ResultBody getNameList() {
        return ResultBody.success(sparePartsInventoryService.getNameList());
    }

    @PostMapping("/export")
    @ApiOperation(value = "数据导出", response = ResultBody.class)
//    @FrequencyControl(time = 15, count = 2, target = FrequencyControl.Target.IP)
//    @FrequencyControl(time = 30, count = 5, target = FrequencyControl.Target.IP)
    public void export(@RequestBody DeviceAllPageReq deviceAllPageRea, HttpServletResponse response) {
        sparePartsInventoryService.export(deviceAllPageRea, response);
    }


    @GetMapping("getSelectList")
    @ApiOperation(value = "仓库物品名称物品编号联动", response = ResultBody.class)
    public ResultBody getSelectList() {
        return ResultBody.success(sparePartsInventoryService.list(Wrappers.<SparePartsInventory>lambdaQuery().select(SparePartsInventory::getSparePartsName, SparePartsInventory::getSparePartsNumber, SparePartsInventory::getWarehouseName)));
    }

}
